package com.tlvip;

import java.util.Scanner;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>description：</p>
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary： </p>
 * <p>instructions： </p>
 * Date 2/25/21</p>
 * Author mac
 *
 * @version 1.0
 */
public class Result {
    public static void main(String[] args) {
//        System.out.println(patten("user_1232@domain.extension"));
        System.out.println(patten("user_1232"));

//        testGetBalanceNum();

        // 测试素数
//        testIsPrime();
    }


    public static boolean patten(String mailBox) {
        String regex = "[a-z]" + "[_]" + "[0-4]";
        return Pattern.matches(regex, mailBox);
    }

    public static void testGetBalanceNum() {
        System.out.println(getBalanceNum("())("));
    }

    public static int getBalanceNum(String str) {
        if (str == null || str.equals("")) {
            throw new IllegalArgumentException("str must not be empty");
        }
        if (!str.contains("(") && !str.contains(")")) {
            throw new IllegalArgumentException("str must contains '(' or ')' ");
        }
        char[] values = str.toCharArray();
        int leftNum = 0;
        int rightNum = 0;
        for (char ch : values) {
            if (ch == '(') {
                leftNum++;
            }
            if (ch == ')') {
                rightNum++;
            }
        }
        if (leftNum > rightNum) {
            return leftNum - rightNum;
        } else {
            return rightNum - leftNum;
        }
    }

    public static void testIsPrime() {
        for (int i = 2; i < 24; i++) {
            if (isPrime(i) == 1) {
                System.out.println(i + " is prime");
            } else {
                System.out.println(i + " greater than 1 is " + isPrime(i));
            }
        }
        System.out.println(isPrime(9));
    }

    public static int isPrime(long n) {
        if (n <= 1) {
            throw new IllegalArgumentException("n mast greater than 1");
        }
        if (n == 2) {
            return 1;
        }
        if (n % 2 == 0) {
            return 2;
        }
        for (int i = 3; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                return i;
            }
        }
        return 1;
    }
}
